home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / BITCOUNT.C < prev    next >
Text File  |  1991-09-17  |  326b  |  16 lines

  1. /****** BIT COUNTER *************/
  2. bit_count(x)
  3. {
  4.         int n=0;
  5.  
  6.         if (x) do
  7.                 n++;
  8.         while(x=x&(x-1));
  9.         return(n);
  10. }/*******************************/
  11.  
  12. /*
  13. ** The loop will execute once for each bit of x set, this is in average
  14. ** twice as fast as the shift/test method.
  15. */
  16.